package cn.yeyiu.sexyiu.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.MutableLiveData;

import cn.yeyiu.netonlinevideo.activity.OnlineMainActivity;
import cn.yeyiu.sexyiu.R;
import cn.yeyiu.sexyiu.activity.SearchActivity;
import cn.yeyiu.sexyiu.task.InitIPTask;
import cn.yeyiu.util.MediaUtil;
import cn.yeyiu.util.VideoUtil;
import cn.yeyiu.util.bean.VideoInfo;
import cn.yeyiu.videoplayer.VideoPlayerActivity;
import com.bumptech.glide.Glide;

public class MainFragment extends Fragment {
    private Spinner optionSpin;
    private LinearLayout searchView;
    private ImageView syncIpIv;
    private ImageView netVideoIv;
    private LinearLayout videoCard;
    private ImageView videoImg;
    private final MutableLiveData<VideoInfo> videoLd = new MutableLiveData<>();
    private TextView videoTitleTv;

    @Override // androidx.fragment.app.Fragment
    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        View inflate = layoutInflater.inflate(R.layout.fragment_main, viewGroup, false);
        viewInit(inflate);
        eventInit();
        return inflate;
    }

    /* access modifiers changed from: package-private */
    public void viewInit(View view) {
        this.searchView = (LinearLayout) view.findViewById(R.id.search_hint_view);
        this.videoCard = (LinearLayout) view.findViewById(R.id.video_card_ll);
        this.videoTitleTv = (TextView) view.findViewById(R.id.data_title_tv);
        this.videoImg = (ImageView) view.findViewById(R.id.data_pic_img);
        this.syncIpIv = (ImageView) view.findViewById(R.id.sync_ip_iv);
        this.netVideoIv = (ImageView) view.findViewById(R.id.net_video_view);
        this.optionSpin = (Spinner) view.findViewById(R.id.option_spin);
    }

    /* access modifiers changed from: package-private */
    public void eventInit() {
        this.videoLd.observe(getViewLifecycleOwner(), videoInfo->{
            MediaUtil.fixLocalVideoInfo(videoInfo);

            this.videoTitleTv.setText(videoInfo.title);
            Glide.with(this).load(videoInfo.picSrc).into(this.videoImg);
            this.videoImg.startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.anim_view_in));
        });

        this.searchView.setOnClickListener(new View.OnClickListener() {
            /* class cn.yeyiu.sexyiu.fragment.MainFragment.AnonymousClass1 */

            public void onClick(View view) {
                MainFragment.this.startActivity(new Intent(MainFragment.this.getActivity(), SearchActivity.class));
            }
        });

        this.videoCard.setOnLongClickListener(new View.OnLongClickListener() {
            public boolean onLongClick(View view) {
                VideoUtil.postRandomVideo(MainFragment.this.optionSpin.getSelectedItem().toString(), MainFragment.this.videoLd);
                return true;
            }
        });
        this.videoCard.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                if (MainFragment.this.videoLd.getValue() != null) {
                    MediaUtil.playVideo(MainFragment.this.getContext(), VideoPlayerActivity.class, MainFragment.this.videoLd.getValue());
                }
            }
        });
        this.syncIpIv.setOnClickListener(v->{
            new InitIPTask(getActivity()).execute();
        });
        this.netVideoIv.setOnClickListener(v->{
            startActivity(new Intent(getContext(), OnlineMainActivity.class));
        });
    }
}
